const { defineConfig } = require('@vue/cli-service');
const path = require('path')
const resolve = dir => path.join(__dirname, dir)



module.exports = defineConfig({
  transpileDependencies: true,
  publicPath: './',
  // 打包的输出目录
  outputDir: '_dist',
  // 保存时是否校验
  lintOnSave: true,
  // 如果文件等设置
  pages: {
    index: {
      entry: 'src/main.js',
      template: 'public/index.html',
      filename: 'index.html'
    }
  },
  // 静态资源打包路径
  assetsDir: 'static',
  // 默认false 可以加快打包
  productionSourceMap: false,
  // 打包后的启动文件
  indexPath: 'index.html',
  // 打包文件是否使用hash
  filenameHashing: true,
  runtimeCompiler: false,
  transpileDependencies: [],
  // 打包的css路径及命名
  /*   css: {
      modules: false,
      // vue 文件中修改css 不生效 注释掉 extract:true
      extract: {
        filename: 'style/[name].[hash:8].css',
        chunkFilename: 'style/[name].[hash:8].css'
      },
      sourceMap: false,
      loaderOptions: {
        css: {},
        less: {
          // 向全局less样式传入共享的全局变量
        },
        // postcss 设置
        postcss: {
          plugins: [
            require("postcss-px-to-viewport")({
              unitToConvert: 'px',
              viewportWidth: 320,
              viewportHeight: 1334,
              unitPrecision: 5,
              propList: ['*'],
              viewportUnit: 'vw',
              fontViewportUnit: 'vw',
              selectorBlackList: ['.ignore'],
              minPixelValue: 1,
              mediaQuery: false,
              replace: true,
              exclude: undefined,
              include: undefined,
              landscape: false,
              landscapeUnit: 'vw',
              landscapeWidth: 568
            })
          ]
        }
      }
  
    }, */
  // webpack 链式配置 默认已经配置好了 node_moudles/@vue
  chainWebpack: config => {
    // 修复HMR
    config.resolve.symlinks(true);
    // 添加别名
    config.resolve.alias
      .set('@', resolve('src'))
      .set('assets', resolve('src/assets'))
      .set('components', resolve('src/components'))
      .set('layout', resolve('src/layout'))
      .set('base', resolve('src/base'))
      .set('static', resolve('src/static'))

    // 压缩图片
    /* config.module
      .rule('images')
      .use('image-webpack-loader')
      .loader('image-webpack-loader')
      .options({
        mozjpeg: { progressive: true, quality: 65 },
        optipng: { enabled: false },
        pngquant: { quality: '65-90', speed: 4 },
        gifsicle: { interlaced: false },
        webp: { quality: 75 }
      }) */

  }


})
